package com.inspectortime.webapp.inspector.fee;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.repository.Repository;
import com.inspectortime.webapp.util.HttpSessionUtils;

/**
 * @author mkvalsvik
 *
 */
public class FeeWizardAdvancedPlanController implements Controller {

	private Repository repository;

	public ModelAndView doPost(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView("redirect:feeWizardAdjusters.html");
		return mv;
	}
	
	public ModelAndView doGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
		FeeWizardAdvancedPlanHelper helper = new FeeWizardAdvancedPlanHelper();
		FeeUtils.storeAdvancedFeeWizardInSession(request, helper);
		
		InspectorCompany company = HttpSessionUtils.retrieveLoggedInCompany(request, repository);
		ModelAndView mv = new ModelAndView("inspector/fee/advancedPlan");
		mv.addObject("inspectorCompany", company);
		mv.addObject("calculators", company.getFeeCalculators());
		return mv;
	}	
		
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		if (request.getMethod().equalsIgnoreCase("get")) {
			return doGet(request, response);
		}
			return doPost(request, response);
	}

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

}
